//
//  ViewController.swift
//  PPCollection
//
//  Created by zmj27404 on 16/5/28.
//  Copyright © 2016年 zmj27404. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var mycollectionView: UICollectionView!
    @IBOutlet weak var flowLayout: UICollectionViewFlowLayout!
    var colors = [UIColor]()
    override func viewDidLoad() {
        super.viewDidLoad()

        for _ in 0...10 {
            colors.append(UIColor.init(red: CGFloat(arc4random()%255)/255.0, green:CGFloat(arc4random()%255)/255.0, blue:CGFloat(arc4random()%255)/255.0, alpha:1.0))
        }
        mycollectionView.backgroundColor = UIColor.whiteColor()
        mycollectionView.reloadData()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

extension ViewController: UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 1
    }
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return colors.count
    }
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView .dequeueReusableCellWithReuseIdentifier("cellID", forIndexPath: indexPath)
        cell.contentView.backgroundColor = colors[indexPath.row]
        return cell
    }
    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
        return CGSizeMake(CGRectGetWidth(collectionView.frame) / 3, CGRectGetHeight(collectionView.frame))
    }
}

